package org.cms.call;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

/**
 * Created by elnoa on 28/10/14.
 */
public class GetEventsCall extends AbstractCall<HttpGet> {

    private String calendarId;

    public GetEventsCall(String accessToken, String calendarId, HttpClient httpClient) {
        super(httpClient, accessToken);
        this.calendarId = calendarId;
    }

    public GetEventsCall invoke(){
        URI getEventsUrl = null;
        try {
            getEventsUrl = new URIBuilder()
                    .setScheme("https")
                    .setHost("www.googleapis.com")
                    .setPath("/calendar/v3/calendars/"+this.calendarId +"/events")
                    .setParameter("access_token", getAccess_token())
                    .build();

        setRequest(new HttpGet(getEventsUrl));


        setResponse(getHttpclient().execute(getRequest()));
        } catch (IOException e) {
            e.printStackTrace();
        } catch (URISyntaxException e) {
            e.printStackTrace();
        }

        return this;
    }
}